#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <BEntry>
#include <BIcon>
#include <BImage>
#include <BButton>
#include <BLineEdit>
#include <BTreeWidget>
#include <BTextEdit>
#include <BFileDialog>
#include <BMessageBox>
#include <BMenuBar>
#include <BMenu>
#include <BSonNode>
#include <BXmlNode>
#include <BStatusBar>
#include <BMainWindow>

#include "ContentBoard.h"
#include "PropertyBoard.h"

using namespace BWE;

class HeadInfo : public BThing
{
public:
	BEntryHolder	headEntry;
	BEntryHolder	htmlEntry;
};

class MainWindow : public BMainWindow
{
public:
	MainWindow();
	~MainWindow();

	bool openFile(const BString& fileName);
	bool saveFile(const BString& fileName);

protected:
	void initMenus();
	void signTitleChanged(bool changed);
	BString findValidName(const char* name, const BTreeItem* parent = 0);
	BSonNode* createSonNode(const BTreeItem* item);
	BXmlNode* createXmlNode(const BTreeItem* item);
	BTreeItem* createTreeItem(const BSonNode* node);
	BTreeItem* createTreeItem(const BXmlNode* node);
	void cleanLostItems(BTreeItem* item);
	void freshItemIcons(BTreeItem* item);
	void refreshResource(BTreeItem* item);
	void cleanResource(BTreeItem* item);
	void writeResource(BTreeItem* item, BString& infos, BString& datas);
	void checkResource(BTreeItem* item, BString& infos);

protected:
	void slotBrowseButtonClicked(BObject* object, const BValue& value);
	void slotLineEditFinished(BObject* object, const BValue& value);
	void slotTargetEditFinished(BObject* object, const BValue& value);
	void slotOutputEditDoubleClicked(BObject* object, const BValue& value);
	void slotTreeItemSelected(BObject* object, const BValue& value);
	void slotTreeItemClicked(BObject* object, const BValue& value);
	void slotTreeItemRightClicked(BObject* object, const BValue& value);
	void slotTreeItemDoubleClicked(BObject* object, const BValue& value);
	void slotWorkspaceDragged(BObject* object, const BValue& value);
	void slotWorkspaceDragMoved(BObject* object, const BValue& value);
	void slotWorkspaceDragDropped(BObject* object, const BValue& value);

	void slotNewActionTriggered(BObject* object, const BValue& value);
	void slotOpenActionTriggered(BObject* object, const BValue& value);
	void slotSaveActionTriggered(BObject* object, const BValue& value);
	void slotSaveAsActionTriggered(BObject* object, const BValue& value);
	void slotCheckActionTriggered(BObject* object, const BValue& value);
	void slotBuildActionTriggered(BObject* object, const BValue& value);
	void slotResourceActionTriggered();

	void slotAddFilesActionTriggered(BObject* object, const BValue& value);
	void slotAddFolderActionTriggered(BObject* object, const BValue& value);
	void slotAddFilterActionTriggered(BObject* object, const BValue& value);
	void slotRefreshActionTriggered(BObject* object, const BValue& value);
	void slotCleanActionTriggered(BObject* object, const BValue& value);
	void slotRemoveActionTriggered(BObject* object, const BValue& value);

	void slotDeleteShortcutTriggered();

protected:
	virtual void closeEvent(const BEvent& event);

	virtual void updateEvent(const BEvent& event);

	virtual void styleEvent(const BEvent& event);

private:
	BMenuBar*				_menuBar;
	BMenu*					_fileMenu;
	BMenu*					_editMenu;
	BMenu*					_viewMenu;
	BMenu*					_toolMenu;
	BMenu*					_itemMenu;
	BAction*				_addFilesAction;
	BAction*				_addFolderAction;
	BAction*				_addFilterAction;
	BAction*				_refreshAction;
	BAction*				_cleanAction;
	BAction*				_removeAction;
	BLineEdit*				_lineEdit;
	ContentBoard*			_contentWidget;
	PropertyBoard*			_propertyGroupBox;
	BStatusBar*				_statusBar;

	BButton*				_openButton;
	BButton*				_saveButton;
	BButton*				_saveAsButton;
	BButton*				_removeButton;
	BButton*				_checkButton;
	BButton*				_buildButton;
	BLineEdit*				_targetEdit;
	BButton*				_browseButton;

	BTreeWidget*			_treeWidget;
	BTextEdit*				_outputEdit;
	int						_freshCount;
	int						_cleanCount;

	BFileDialogHolder		_fileDialog;
	BMessageBoxHolder		_messageBox;
};

#endif